package edu.ycxy.poetry.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.ycxy.poetry.entity.Writer;
import edu.ycxy.poetry.vo.AddKnowVo;
import edu.ycxy.poetry.vo.AddPoetsVo;
import edu.ycxy.poetry.vo.UpdatePoetVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author @xin
 * @createDate 2022/3/8
 * @Description
 */
@Repository
public interface WriterMapper extends BaseMapper<Writer> {

    //根据作者的姓名查询作者的详细信息
    @Select("select * from vab_writer where name=#{name}")
    Writer findByName(String WriterName);


    //查询所有的作者信息
    @Select("select * from vab_writer")
    List<Writer> selectListAuthor();

    //根据作者的朝代信息查询相关的作者
    @Select("select * from vab_writer where dynasty=#{name}")
    List<Writer> selectListByName(String DyName);

    // 添加作者信息
    @Insert("insert vab_writer(name) values (#{author})")
    Integer insertAuthor(String author);

    // 添加作者的详细信息
    @Insert("insert into vab_writer(name,txt,dynasty) values (#{name},#{txt},#{dynasty})")
    Integer addPoet(AddPoetsVo addPoetsVo);

    //对诗人进行模糊查询
    @Select("select * from vab_writer where name like CONCAT ('%',#{name},'%')")
    List<Writer> findListByName(String name);

    // 删除
    @Delete("delete from vab_writer where id=#{id}")
    void deleteById(Integer id);

    @Select("select * from vab_writer where id=#{id}")
    Writer findOneById(Integer id);

    @Update("update vab_writer set name=#{name},txt=#{txt},dynasty=#{dynasty} where id=#{id}")
    Integer updatePoet(UpdatePoetVo updatePoetVo);
}
